/* ---------------------------------------------------------------
 "Euroscepticism and Bargaining Success in the European Union" Replication
 
- Authors: Nathan Mariano and Christina Schneider                  
- Date: 5-25-21
- Output: results_main.tex, results_robust_RR.tex, results_robust1_RR.tex,
          results_robust2.tex, sumstat.tex, conflict_RR2.eps,
          governmentsupport_RR2.eps, marginsplot_scepticism_RR2.eps,
          publicsupport_RR2.eps, success_RR2.eps
- Notes: This code replicates the results for the above paper. Contact information
         and variable descriptions contained in codebook.
------------------------------------------------------------------*/ 


version 14.2
set more off
*cd "/Users/christinaschneider/Dropbox (The Slantchev Family)/Work/Projects/Working Papers/Bargaining Success/R&R v2 Analysis"
cd "/Users/nathanmariano/Dropbox/Bargaining Success/JEPP/Final Submission/Replication Package"

use BargainingData.dta, clear

global mainvar success_new
global controlvars positiondistance_coun  positiondistance_ep positiondistance_com population_log salience_rel

/* Main results */ 

* pro-EU governments facing negative public opinion

*main
mixed $mainvar conflict_pos  $controlvars   || prnrnmc:, var robust mle
estimates store m1

*different DV
mixed success_rel  conflict_pos  positiondistance_coun  positiondistance_ep positiondistance_com population_log   || prnrnmc:, var robust mle
estimates store m2

mixed $mainvar   conflict_neg $controlvars   || prnrnmc:, var robust mle
estimates store m3

mixed $mainvar gov_eu_cmp_static eu_avg  $controlvars  || prnrnmc:, var mle 
estimates store m4

mixed $mainvar   conflict_neg1 $controlvars   || prnrnmc:, var robust mle
estimates store m5


#delimit ;

esttab m1 m2 m3 m4 m5 using results_main.tex, replace modelwidth(10) addnote("Standard errors in parentheses") 
 starlevels(* 0.10 ** 0.05) mlabel("Model 1" "Model 2" "Model 3" "Model 4" "Model 5") 
legend cells(b(star fmt(3)) se(par)) stats(chi2 N, star labels("Wald test" "Observations") )
label varwidth(30)  collabels(none);

#delimit cr


/* Robustness checks */ 

*Control variables
mixed $mainvar  conflict_pos  positiondistance_coun  positiondistance_ep positiondistance_com salience_rel positiondistance_refpt gdp_log qmv newmember involved_dum || prnrnmc:, var robust mle
estimates store m6

*placebo and main
mixed $mainvar  conflict_pos conflict_neg $controlvars || prnrnmc:, var mle 
estimates store m7

*previous period
mixed $mainvar  conflict_pos  $controlvars if finyear<2009 || prnrnmc:, var robust mle
estimates store m8

*time fixed effects
mixed $mainvar  conflict_pos  $controlvars i.finyear || prnrnmc:, var robust mle
estimates store m9

*Absolute Salience
mixed $mainvar  conflict_pos  salience positiondistance_coun  positiondistance_ep positiondistance_com   population_log  || prnrnmc:, var robust mle
estimates store m10

*worst possible success
mixed $mainvar  conflict_pos  $controlvars success_min || prnrnmc:, var robust mle
estimates store m11

mixed $mainvar conflict_pos eu_avg gov_eu_cmp_static  $controlvars  || prnrnmc:, var mle 
estimates store m12

mixed $mainvar conflict_pos_alt  $controlvars   || prnrnmc:, var robust mle
estimates store m13

mixed $mainvar conflict_pos_alt1  $controlvars   || prnrnmc:, var robust mle
estimates store m14

*alternative DV
mixed success_rel1 conflict_pos  $controlvars   || prnrnmc:, var robust mle
estimates store m15

*pos/pos
mixed $mainvar  conflict_pos3 $controlvars   || prnrnmc:, var robust mle
estimates store m16

*log scaled third quartile
mixed $mainvar conflict_log_3Q  $controlvars   || prnrnmc:, var robust mle
estimates store m18

* Multiple Imputation: using other variables to predict missingness on gov_eu_cmp_static 

global predvars  gdp_log gdppc gov_planeco_cmp_static gov_markeco_cmp_static ///
				gov_plan_econ_cmp gov_free_market_cmp_static ///
				gov_st_involvement_cmp gov_welfare_cmp_static gov_lr_cmp_static
				
rename gov_state_involvement_cmp_static gov_st_involvement_cmp
rename gov_planned_economy_cmp_static gov_plan_econ_cmp

mi set mlong
mi register imputed gov_eu_cmp_static $controlvars $predvars
mi xtset, clear
mi impute mvn gov_eu_cmp_static $controlvars $predvars, add(10) rseed (53421)

gen gov_eu_imp=.
replace gov_eu_imp=1 if gov_eu_cmp_static>=0
replace gov_eu_imp=0 if gov_eu_cmp_static<0
replace gov_eu_imp=. if gov_eu_cmp_static==.

gen conflict_imp=0
replace conflict_imp = 1 if gov_eu_imp==1 & pub_eu==0
replace conflict_imp = . if gov_eu_imp ==. | pub_eu==.

label variable conflict_imp  "Conflict (Imputed)"

mi estimate, post: mixed $mainvar conflict_imp  $controlvars   || prnrnmc:, var robust mle
estimates store m17


/* Exporting new models */

#delimit ;

esttab m6 m7 m8 m9 m10  using results_robust_RR.tex, replace modelwidth(10) addnote("Standard errors in parentheses") 
 starlevels(* 0.10 ** 0.05) mlabel("Model 1" "Model 2" "Model 3" "Model 4" "Model 5")
legend cells(b(star fmt(3)) se(par)) stats(chi2 N, star labels("Wald test" "Observations") )
label varwidth(30)  collabels(none);

#delimit cr

#delimit ;

esttab m11 m12 m13 m14 m15 using results_robust1_RR.tex, replace modelwidth(10) addnote("Standard errors in parentheses") 
 starlevels(* 0.10 ** 0.05) mlabel("Model 6" "Model 7" "Model 8" "Model 9" "Model 10")
legend cells(b(star fmt(3)) se(par)) stats(chi2 N, star labels("Wald test" "Observations") )
label varwidth(30)  collabels(none);

#delimit cr

#delimit ;

esttab m16 m17 m18 using results_robust2_RR.tex, replace modelwidth(10) addnote("Standard errors in parentheses") 
 starlevels(* 0.10 ** 0.05) mlabel("Model 11" "Model 12" "Model 13" "Model 14")
legend cells(b(star fmt(3)) se(par)) stats(chi2 N, star labels("Wald test" "Observations") )
label varwidth(30)  collabels(none);

#delimit cr

/* Figures & Other Tables */ 

use BargainingData.dta, clear

label define countrylb 1 "Belgium" 2 "Denmark" 3 "Germany" 4 "Greece" 5 "Spain" 6 "France" 7 "Ireland" ///
8 "Italy" 9 "Luxembourg" 10 "Netherlands" 11 "Austria" 12 "Portugal" 13 "Finland" 14 "Sweden" 15 "United Kingdom" ///
16 "Cyprus" 17 "Malta" 18 "Czech Republic" 19 "Poland" 20 "Slovenia" 21 "Slovakia" 22 "Hungary" 23 "Bulgaria" ///
24 "Romania" 25 "Estland" 26 "Latvia" 27 "Lithuania" 28 "Croatia"

label values country_id countrylb

* Success by member state 
ciplot success_new, by(country_id) xline(65.2, lpattern(dash)) horizontal scheme(s1mono) xtitle(Success) ytitle("") 
graph export success_RR2.eps, replace

* Distribution of obs by EU support (citizens) and EU support (gov) 
twoway scatter gov_eu_cmp_static eu_avg,  xline(0) yline(0) scheme(s1mono) xtitle(EU Support (Citizens)) ytitle(EU Support (Governments))
graph export conflict_RR2.eps, replace

* Summary statistics for appendix 
local controlvars positiondistance_coun  positiondistance_ep positiondistance_com population_log salience_rel
quietly gen x = uniform()
quietly regress x success_new  conflict_pos conflict_neg gov_eu_cmp_static eu_avg `controlvars' positiondistance_refpt gdp_log qmv salience newmember involved_dum success_rel success_min
estadd summ, mean sd min max

esttab using sumstat_RR2.tex, replace  cells("mean sd min max") stats(N) drop(_cons) mlabels(,none) label varwidth(30)
drop x


* Government EU Support by member state
ciplot gov_eu_cmp_static, by(country_id) horizontal scheme(s1mono) xtitle(EU Support (Government)) ytitle("") 
graph export governmentsupport_RR2.eps, replace

* Public EU Support by member state
ciplot eu_avg, by(country_id) xline(0, lpattern(dash)) horizontal scheme(s1mono) xtitle(EU Support (Public)) ytitle("") 
graph export publicsupport_RR2.eps, replace


* Marginal Effects Plot

local mainvar success_new
local controlvars positiondistance_coun  positiondistance_ep positiondistance_com population_log salience_rel

summarize eu_neg
local MyMin = r(min)
local MyMax = r(max)
local Grid = (`MyMax'-`MyMin')/100

local mainvar success_new
local controlvars positiondistance_coun  positiondistance_ep positiondistance_com population_log salience_rel

mixed `mainvar' gov_eu eu_neg  `controlvars'  || prnrnmc:, var mle 
margins, at(gov_eu=1 c.eu_neg = (`MyMin' (`Grid') `MyMax'))
marginsplot, scheme(s1mono) legend(off) title("") xtitle("Euroscepticism") ytitle("Predicted Success") xscale(range(`MyMin' `MyMax'))
graph export marginsplot_scepticism_RR2.eps, replace



